﻿/*! @file extdevice.h
  * @brief Defines class ExtDevice
  * @author AK
  * @date 08.08.2012
  */

#ifndef EXTDEVICE_H
#define EXTDEVICE_H

#include <QObject>
#include <QProcess>

class ExtDeviceDlg;
class ProviderDlg;

/**
 * @brief Definition of ExtDevice Class
 *
 * @class ExtDevice extdevice.h "PlacesParser/extdevice.h"
 */
class ExtDevice : public QObject
{
    Q_OBJECT

public:
    ExtDevice(QObject* parent = 0);         // ctor
    ~ExtDevice();                           // dtor

    // Device Infos
    QString     deviceDisplayId;
    QString     deviceFirstboot;
    QString     deviceIsoCountry;
    QString     deviceManufacturer;
    QString     deviceModel;
    QString     deviceModversion;
    QString     deviceNetworkType;
    QString     deviceOperatorAlpha;
    QString     deviceRooted;
    QString     deviceSerialNr;
    QString     deviceStatus;
    QString     deviceUId;
    QString     deviceVersionRelease;

public Q_SLOTS:
    QList<QString> getDevices();            // get attached devices

Q_SIGNALS:
    void deviceListReady(QList<QString> devlst);    // emitted when device list is ready
    void expoReady(QString baseDir,
                   QString expoDir,
                   QString deviceId);
    void gotDevice(QString dev);                    // forwards gotDevice from Dlg to Main

private:
    QProcess        *adbProcess;                // adb Process instance
    QList<QString>  arguments;                  // arguments to adb command
    QString         baseDir;                    // dir to write to ini file
    QString         buffer;                     // just a buffer
    QString         command;                    // command to adbProcess
    int             counter;
    QList<QString>  deviceLst;                  // list of connected devices
    ExtDeviceDlg    *extDevDlg;                 // Dialog object
    ProviderDlg     *providerDlg;               // Dialog object
    //    QByteArray expoOutput;
    int             idxProcess;                 // my Process ID < arguments.size()
    QList<QString>  sqliteFiles;                // list of files to export
    QString         selectedDevice;             // selected device for file expo
    QString         selectedDir;                // selected dir for file expo
    QByteArray      version;                    // adb version string

    QList<QString> parseDevicesResult(QString buf); // parse result for QComboBox

private Q_SLOTS:
    QString         expoDirChanged(QString);
    void            finishedProcess(int exitCode,
                                QProcess::ExitStatus exitStatus);
    void            getFiles(QString dev, QString dir);     // pull files from device
    void            getProperties(QString dev);             // read device properties
    QList<QString>  getStatus(QString dev);
    void            on_done();                              // we're done
    void            on_logRequest(QString dev);             // PushButton reaction
    void            on_propertiesRequest(QString dev);      // PushButton reaction
    void            on_providerRequest(QString dev);        // PushButton reaction
    void            on_providersReady(QList<QString> providers);
    void            on_reloadDevices(QString);              // uid stuff for now
    void            parsePropertiesResult();                // sets device Info variables
    void            parseProviderResult();                  // build list of providers
    void            sendDeviceToMainWindow(QString dev);    // Device ID used
    void            stdoutMsg();                            // read Stdout from Process
    void            stderrMsg();                            // read Stderr from Process

};

#endif // EXTDEVICE_H
